package com.erp.module.xianChangPaiZhao

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.bean.AnZhuangphotoBean
import com.erp.bean.PhotoBean
import com.erp.contacts.Contacts
import com.erp.util.Httputil
import com.erp.util.Httputil.Call
import com.erp.util.Httputil.getparams
import org.xutils.http.RequestParams
import org.xutils.x
import java.io.File

/**
 * Created by Administrator on 2019/3/19/019.
 * 作者：刘洋
 */
class XianChangPaiZhapModel {
    /**获取安装管理列表*/
    fun getanzhuangphoto(context: Context, page: Int, pagesize: Int, searchParams: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.ANZHUANG_PHOTO)
        getparams(context, params)
        Httputil.setProsess(params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        params.addBodyParameter("searchParams[onum]", searchParams)
        Log.d("TAAAG", "se=$searchParams")
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }

    fun setAnZhuang(context: Context, bean: AnZhuangphotoBean,oid: String, onUserDataInterface: OnUserDataInterface) {
        var params = RequestParams(Contacts.ANZHUANG_PHOTO+"/"+oid+"/edit_isl")
        getparams(context, params)
        Httputil.addtoken(params)
        Httputil.setProsess(params)
        params.addHeader("ACCEPT", "application/json")
        Log.d("TAAAG", bean.toString())
        params.addBodyParameter("", "", Contacts.BOUNDARY)
        params.addBodyParameter("isl_asp", bean.isl_asp, Contacts.BOUNDARY)
        for (i in bean.listphoto.indices) {
            val photo = bean.listphoto[i]
            if (photo.fid == "") {
                params.addBodyParameter("files[new][$i]", File(photo.uri), Contacts.BOUNDARY)
            }
        }
        x.http().post(params, Call(context, onUserDataInterface))
    }
    fun deleteAnZhuang(context: Context,oid: String,photobean : PhotoBean, onUserDataInterface: OnUserDataInterface) {
        var params = RequestParams(Contacts.ANZHUANG_PHOTO+"/"+oid+"/edit_isl")
        getparams(context, params)
        Httputil.addtoken(params)
        Httputil.setProsess(params)
        params.addHeader("ACCEPT", "application/json")
        params.addBodyParameter("", "", Contacts.BOUNDARY)
        params.addBodyParameter("files[delete][" + photobean.fid + "]", photobean.fid, Contacts.BOUNDARY)
        x.http().post(params, Call(context, onUserDataInterface))
    }


    /**获取安装信息*/
    fun getAnZhuangXingxi(context: Context, oid: String, onUserDataInterface: OnUserDataInterface){
        var params = RequestParams(Contacts.ANZHUANG_XPHOTO + oid)
        getparams(context, params)
        Log.d("getAnZhuangXingxi","p="+params.toString())
        x.http().get(params, Call(context, onUserDataInterface))
    }


    fun cabinetTrialErection(context: Context,cid : String,problem:String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.CABINET_TRIAL_ERECTION+cid)
        getparams(context, params)
        params.addBodyParameter("problem",problem)
        params.addHeader("ACCEPT", "application/json");
        x.http().post(params, Call(context, onUserDataInterface))
    }

    fun deleteCabinetTrialErection(context: Context, cid : String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.DELETE_CABINET_TRIAL_ERECTION+cid)
        getparams(context, params)
        params.addHeader("ACCEPT", "application/json");
        x.http().post(params, Call(context, onUserDataInterface))
    }
}